package com.hrg.rds.infra.connect.protocol.s7;

import cn.hutool.extra.tokenizer.Word;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum S7DataType {

	BOOL("X", "Bit", "Single boolean value", "All"),
	WORD("W", "Word", "Array of 16 boolean values", "All"),
	DWORD("D", "Double-Word", "Array of 32 boolean values", "All"),
	INT("I", "Integer", "16 bit integer (signed)", "All"),
	DINT("D", "Double integer", "32 bit integer (signed)", "All"),
	REAL("D", "Real", "32 bit IEEE 754 full precision floating point value (signed)", "All"),
	CHAR("B", "Character", "8 bit character", "All"),
	STRING("X", "String", "String 2 + n bytes", "All"),
	TIME("X", "Time", "Time (like in duration) (Minutes, Seconds, Milliseconds)", "All"),
	DATE("X", "Date", "Date", "All"),
	TIME_OF_DAY("X", "Time of day", "Time (like in 4:40PM)", "All")
	;
	S7DataType(String shortCode, String name, String description, String supportPlcType) {
		this.shortCode = shortCode;
		this.name = name;
		this.description = description;
		this.supportPlcType = supportPlcType;
	}
	private final String shortCode;
	private final String name;
	private final String description;
	private final String supportPlcType;

	private static final Map<String, S7DataType> map = new HashMap<>();
	
	static {
		for (S7DataType s7DataType : S7DataType.values()) {
			map.put(s7DataType.name(), s7DataType);
		}
	}

	public static S7DataType get(String name) {
		return map.get(name);
	}

}
